package com.lzx.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzx.shop.dao.ProductDetailDao;
import com.lzx.shop.dataobject.ProductDetailDO;
import com.lzx.shop.service.ProductDetailService;
import com.lzx.shop.utils.UUIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘正星
 * @version 1.0.0
 * @ClassName ProductDetailServcieImpl.java
 * @Description TODO
 * @createTime 2021年03月21日 14:48:00
 */
@Service
public class ProductDetailServcieImpl implements ProductDetailService {
    @Autowired
    private ProductDetailDao productDetailDao;

    @Override
    public boolean save(ProductDetailDO productDetailDO) {
        if (StringUtils.isBlank(productDetailDO.getId())){
            productDetailDO.setId(UUIDUtil.getUUID());
            return productDetailDao.insert(productDetailDO)>0;
        }
        return productDetailDao.updateById(productDetailDO)>0;

    }

    @Override
    public List<ProductDetailDO> findAll() {
        return productDetailDao.selectList(null);
    }

    @Override
    public ProductDetailDO findById(String id) {
        return productDetailDao.selectById(id);
    }

    @Override
    public boolean update(ProductDetailDO productDetailDO) {
        return productDetailDao.updateById(productDetailDO)>0;
    }

    @Override
    public ProductDetailDO findByProductId(String id) {
        return productDetailDao.selectOne(new QueryWrapper<ProductDetailDO>().eq("product_id",id));
    }

    @Override
    public boolean DeleteById(String id) {
        return productDetailDao.deleteById(id)>0;
    }

    @Override
    public List<ProductDetailDO> query(QueryWrapper queryWrapper) {
        return productDetailDao.selectList(queryWrapper);
    }
}
